from dataclasses import dataclass

from src.application.order.converters import convert_order_entity_to_dto
from src.application.order.dto.order import OrderDTO
from src.application.order.uow import OrderUoW
from src.domain.order.value_objects import OrderId


@dataclass(frozen=True)
class GetOrder:
    order_id: int


class GetOrderHandler:
    """
    Получение заказа по id
    """

    def __init__(self, *, uow: OrderUoW) -> None:
        self._uow = uow

    async def __call__(self, command: GetOrder) -> OrderDTO:
        order_id = OrderId(command.order_id)
        order = await self._uow.order_repo.acquire_order_by_id(order_id)

        order_dto = convert_order_entity_to_dto(order)

        return order_dto
